
package core{
import com.greensock.TweenLite;

import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.MouseEvent;

import ru.cjay.loading.ResourceManager;


public class AGameObject extends Sprite {

    private var _hint:String = null;
    private var _hintMC:MovieClip = null;
    public function AGameObject() {
        addEventListener(MouseEvent.MOUSE_MOVE, showHint);
        addEventListener(MouseEvent.MOUSE_OUT, hideHint);
    }

    public function update():void
    {

    }

    public function destroy():void
    {

    }

    private function showHint(event:MouseEvent):void{
        if (_hintMC==null) return;

        var st:Stage =Facade.getInstance().stage;
        st.addChild(_hintMC);
        _hintMC.alpha = 1;

        var p_x:int  =  event.stageX+20;
        var p_y:int  =  event.stageY;
        if (p_x+_hintMC.width>Facade.WIDTH) p_x = p_x - _hintMC.width - 30;
        if (p_y+_hintMC.height-150>Facade.HEIGHT) p_y = p_y - _hintMC.height;
        _hintMC.x = p_x;
        _hintMC.y = p_y;
    }

    public function hideHint(event:MouseEvent):void{
        if (_hintMC==null) return;
        TweenLite.to(_hintMC,0.25,{alpha:0,onComplete :function():void{
                    if (Facade.getInstance().stage.contains(_hintMC))  Facade.getInstance().stage.removeChild(_hintMC);
                }
                });


    }

    public function get hint():String {
        return _hint;
    }

    public function set hint(value:String):void {
        _hint = value;
         if (_hintMC==null){
            _hintMC = new (ResourceManager.getInstance().getSwfAssetClass("ui:LittleHint") as Class)();
        }
        _hintMC.text.text = _hint;

    }

    public function setHintInstance(mc:MovieClip):void{
        _hintMC = mc;
    }
}
}

